package com.xhtt.smart.card.common.enums;


import com.xhtt.smart.card.common.constant.Contstants;
import com.xhtt.smart.card.common.util.HexConver;
import io.netty.util.internal.StringUtil;

/**
 * 传输类型 上行，下行
 *
 * @author wangze
 * @date 2018-07-04 10:26.
 **/
public enum TransferTypeEnum {


    UP(HexConver.binToByte("00" + Contstants.UP_STR + Contstants.VERSION), "上行"),

    Down(HexConver.binToByte("00" + Contstants.DOWN_STR + Contstants.VERSION), "下行");


    private byte index;
    private String name;

    TransferTypeEnum(byte index, String name) {
        this.index = index;
        this.name = name;
    }

    public byte getIndex() {
        return index;
    }

    public void setIndex(byte index) {
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static TransferTypeEnum getByIndex(byte index) {
        //TODO 这里不判断版本号
        String bin = HexConver.byteToBin(index);
        if (StringUtil.isNullOrEmpty(bin)) {
            return null;
        }

        String type = bin.substring(2, 3);
        if (Contstants.UP_STR.equals(type)) {
            return TransferTypeEnum.UP;
        } else if (Contstants.DOWN_STR.equals(type)) {
            return TransferTypeEnum.Down;
        }
        return null;

    }


}
